﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ProjectTemplateUpdater
{
	public class ProjectTemplateDirectoryUpdater
	{
		private string oldVersion;
		private string newVersion;
		private string templateDirectory;

		public ProjectTemplateDirectoryUpdater(string oldVersion, string newVersion, string templateDirectory)
		{
			this.oldVersion = oldVersion;
			this.newVersion = newVersion;
			this.templateDirectory = templateDirectory;
		}

		public void Update()
		{
			foreach (string file in Directory.GetFiles(templateDirectory))
			{
				if (!file.EndsWith(".zip"))
				{
					continue;
				}

				string tempFileName = file.Replace(".zip", ".New.zip");
				ProjectTemplateZipUpdater zipUpdater = new ProjectTemplateZipUpdater(oldVersion, newVersion, file, tempFileName);

				zipUpdater.Process();

				File.Delete(file);

				File.Copy(tempFileName,file);

				File.Delete(tempFileName);
			}
		}
	}
}
